import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:saas_order_meal/model/site_model.dart';
import 'package:saas_order_meal/net/net_response/elser_week_bind_info.dart';
import 'package:saas_order_meal/net/net_response/site_list_data.dart';
import 'package:saas_order_meal/saas_order_meal.dart';


class SelectPlaceViewModel extends BaseViewModel {
  final dynamic orderModelId;
  final dynamic bindSiteId;
  final dynamic bindUseType;

  // List<SiteListData> siteList = [];
  List<CanUseSiteList> siteList = [];

  SelectPlaceViewModel(BuildContext? context,
      {required this.orderModelId, this.bindSiteId, this.bindUseType,required this.siteList})
      : super(context);

  var siteModel = SiteModel();

  CanUseSiteList? selectSite;

  PickerDataWithIdModel? selectFoodType;

  var foodTypeSelectList = SaasOrderMeal.foodTypeSelectList;


  @override
  void onCreated() {
    if(bindSiteId!=null){
      selectSite = siteList.firstWhere((element) => element.siteId == bindSiteId);
      if(SaasOrderMeal.useNetUseType){
        foodTypeSelectList = selectSite?.useType??[];
      }

    }
    if(bindUseType!=null){
      selectFoodType = foodTypeSelectList.firstWhere((element) => element.pickId==bindUseType.toString());
    }else{
      // selectFoodType = foodTypeSelectList.first;
    }

    super.onCreated();
    // getSiteList();
  }

  // Future<void> getSiteList() async {
  //   showLoadingDialog();
  //   try {
  //     siteList = await siteModel.getSiteList(orderModelId);
  //     hideDialog();
  //     notifyListeners();
  //   } catch (e) {
  //     showToast(e.toNetError());
  //     hideDialog();
  //   }
  // }

  void applySelect() {
    if (selectSite == null) {
      showToast("请选择场所");
      return;
    }
    if (selectFoodType == null) {
      showToast("请选择用餐方式");
      return;
    }
    Go().pop(result: {
      "siteId": selectSite!.siteId.toString(),
      "siteName":selectSite!.siteName,
      "useType": selectFoodType!.pickId,
      "useTypeName":selectFoodType!.name
    });
  }
}
